package butines.kraz.entity;

import java.awt.Graphics2D;

import butines.core.Sprite;
import butines.core.game.AbstractGameEntity;
import butines.core.game.fsm.State;
import butines.core.game.fsm.StateMachine;
import butines.kraz.state.CorpseState;

public class Corpse extends AbstractGameEntity {

	private Unit dead;
	
	private Sprite sprite = new Sprite();

	private StateMachine<Corpse> stateMachine = new StateMachine<Corpse>(this);
	
	public Corpse(Unit dead) {
		this.dead = dead;
		
		getPosition().set(dead.getPosition());
		getForward().set(dead.getForward());
		getSide().set(dead.getSide());
		setRadius(dead.getRadius());
		setViewDistance(dead.getViewDistance());
		
		stateMachine.changeState(CorpseState.getInstance());
	}
	
	public void update(float tpf) {
		sprite.update(tpf);
		stateMachine.update();
	}

	public void draw(Graphics2D g, float offsetX, float offsetY) {
		float xScreen = getPosition().x - offsetX;
		float yScreen = getPosition().y - offsetY;
		float angle = getForward().theta();		
		sprite.draw(g, xScreen, yScreen, angle);
	}

	public void changeState(State<Corpse> newState) {
		stateMachine.changeState(newState);
	}

	public Unit getDead() {
		return dead;
	}

	public Sprite getSprite() {
		return sprite;
	}
	
	
}
